# Maintainer: Patrick Stewart <patstew@gmail.com>
# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=jupyter_console
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=6.4.0
pkgrel=3
pkgdesc='An IPython-like terminal frontend for Jupyter kernels in any language (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/jupyter/jupyter_console'
license=('BSD')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-colorama
    ${MINGW_PACKAGE_PREFIX}-python-ipykernel
    ${MINGW_PACKAGE_PREFIX}-python-ipython
    ${MINGW_PACKAGE_PREFIX}-python-jupyter_client
    ${MINGW_PACKAGE_PREFIX}-python-jupyter_core
    ${MINGW_PACKAGE_PREFIX}-python-prompt_toolkit
    ${MINGW_PACKAGE_PREFIX}-python-pygments
    ${MINGW_PACKAGE_PREFIX}-python-pywin32)
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-python-setuptools)
source=(https://github.com/jupyter/${_realname}/archive/${pkgver}.tar.gz)
sha256sums=('171b4aa83395143269f15bc521e0a8d99bf4b69fdfeeb58a9f7cb4a5b9c7c5f6')

prepare() {
  cd "${srcdir}"
  rm -rf "python-build-${MSYSTEM}" | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  msg "Python build for ${MSYSTEM}"  
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install \
    --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=0  --skip-build

  find "${pkgdir}/" -name "*.pyc" -delete
  find "${pkgdir}/" -type d -empty -delete

  install -Dm644 "COPYING.md" "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  # remove shebang line
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done
}
